package org.dizena.common.base.struct;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TransmittableThreadLocalMap {

    private static final TransmittableThreadLocal<Map<String, String>> INHERITABLE_THREAD_LOCAL = new TransmittableThreadLocal<>() {
        @Override
        protected Map<String, String> initialValue() {
            return new ConcurrentHashMap<>();
        }
    };

    public static Map<String, String> get() {
        return INHERITABLE_THREAD_LOCAL.get();
    }

    public static void set(String key, String value) {
        INHERITABLE_THREAD_LOCAL.get().put(key, value);
    }

    public static void remove() {
        INHERITABLE_THREAD_LOCAL.remove();
    }
}

